package com.xiaomi.controller;

import com.alibaba.fastjson.JSON;
import com.xiaomi.entity.Pay;
import com.xiaomi.model.Result;
import com.xiaomi.service.PayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName PayController
 * @Description TODO
 * @Author lll
 * @Date 2021/12/2 9:53
 * @Version 1.0
 **/
@Controller
@RequestMapping(value = "/Pay", produces  = "text/json;charset=UTF-8")
public class PayController {

    @Autowired
    private PayService payService;

    @GetMapping("/pageSearch.do")
    @ResponseBody
    public String pageSearch(@RequestParam Integer page,
                             @RequestParam Integer limit,
                             @RequestParam(required = false) Integer payId,
                             @RequestParam(required = false) String state){
        Map<String,Object> pars = new HashMap<>();
        pars.put("payId",payId);
        pars.put("state",state);
        if (page!=null && limit!=null){
            pars.put("offset",(page-1)*limit);
            pars.put("limit",limit);
        }
        List<Pay> pays = payService.pageSearch(pars);
        Integer count =payService.getCount(pars);
        Result result = new Result();
        result.setCode(0);
        result.setCount(count);
        result.setData(pays);

        String s = JSON.toJSONString(result);
        return s;
    }
    @GetMapping("/sj.do")
    @ResponseBody
    public String xiugai(Pay pay){
        payService.sjupdate(pay);
        Result result = new Result();
        result.setCode(0);

       result.setMsg("修改成功");

        String s = JSON.toJSONString(result);
        return s;

    }
}
